{extend name="../public/header" /}
{block name="body"}
<body>
{include file="../public/common" /}
<fieldset class="layui-elem-field site-demo-button" style="padding:10px;">
	<div class="layui-row">
		<!--  -->
		<form id="form1" class="layui-form layui-form-pane" action="{:url('')}">
			<section class="panel panel-padding">
				<div class="layui-form-item">
					<label class="layui-form-label">名称</label>
					<div class="layui-input-inline">
						<input type="text" name="rwname" value="{$info.rwname|default=''}" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">等级</label>
					<div class="layui-input-inline">
						<input type="text" id="nlv" name="rwlv" value="{$info.rwlv|default='0'}" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">前置</label>
					<div class="layui-input-inline">
						<input type="hidden" id="lastrwid" name="lastrwid" value="{$info.lastrwid|default='0'}" class="layui-input">
						<input type="text" id="lastrwid_name" value="{$info.lastrwid_name|default=''}" class="layui-input" disabled>
					</div>
					<div class="layui-form-mid layui-word-aux"><a class="layui-btn layui-btn-xs ajax-front" data-url="{:url('getFrontTask')}" data-title="前置">设置</a></div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">介绍</label>
					<div class="layui-input-inline">
						<textarea name="rwinfo" placeholder="请输入介绍" class="layui-textarea">{$info.rwinfo|default=''}</textarea>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">类型</label>
					<div class="block">
						<input type="radio" name="rwlx" {eq name="$info.rwlx" value="1"}checked{/eq} title="普通" value="1" checked />
						<input type="radio" name="rwlx" {eq name="$info.rwlx" value="2"}checked{/eq} title="每日" value="2"/>
						<input type="radio" name="rwlx" {eq name="$info.rwlx" value="3"}checked{/eq} title="主线" value="3"/>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">种类</label>
					<div class="block">
						<input type="radio" lay-filter="rwzl" name="rwzl" {eq name="$info.rwzl" value="1"}checked{/eq} title="收集" value="1" checked />
						<input type="radio" lay-filter="rwzl" name="rwzl" {eq name="$info.rwzl" value="2"}checked{/eq} title="打怪" value="2"/>
						<input type="radio" lay-filter="rwzl" name="rwzl" {eq name="$info.rwzl" value="3"}checked{/eq} title="对话" value="3"/>
					</div>
				</div>
				<fieldset class="layui-elem-field">
					<legend>需求配置</legend>
					<div class="layui-field-box">
						<div class="layui-row">
							<div class="layui-form-item">
								<label class="layui-form-label">模型ID</label>
								<div class="layui-input-inline">
									<input type="text" id="rwyq" name="rwyq" value="{$info.rwyq|default=''}" class="layui-input">
								</div>

								<label class="layui-form-label" id="need_title">名称</label>
								<div class="layui-input-inline">
									<input type="text" id="rwyq_name" value="{$info.rwyq_name|default=''}" class="layui-input" disabled>
								</div>

								<div class="layui-form-mid layui-word-aux">
									<a class="layui-btn layui-btn-xs ajax-mold" data-url="{:url('getMoldList')}" data-alt='1' data-title="需求配置">设置</a>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label" id="need_over">完成目标</label>
								<div class="layui-input-inline">
									<input type="text" id="rwcount" name="rwcount" value="{$info.rwcount|default=''}" class="layui-input">
								</div>
								<div class="layui-input-inline" id="rwcount_show" {if ($info.rwzl != 3)} style="display:none" {/if}>
									<input type="text" id="rwcount_name" value="{$info.rwcount_name|default=''}" class="layui-input" disabled>
								</div>

								<div class="layui-form-mid layui-word-aux" id="rwcount_ff" {if ($info.rwzl != 3)} style="display:none" {/if} >
									<a class="layui-btn layui-btn-xs ajax-mold" data-url="{:url('getMoldList')}" data-alt='2' data-title="完成目标npc">设置</a>
								</div>
							</div>
						</div>
					</div>
				</fieldset>
				<!-- / -->
				<fieldset class="layui-elem-field">
					<legend>奖励</legend>
					<div class="layui-field-box">
						<div class="layui-row" id="rwzb">
							<div class="layui-form-item">
								<label class="layui-form-label">装备</label>
								<button class="layui-btn ajax-reward" data-url="{:url('getMoldList')}" data-type="1" type="button">新增</button>
							</div>
							{foreach name='info.rwzb_list' item='vo'}
							<div class="layui-form-item">
								<label class="layui-form-label">ID</label>
								<div class="layui-input-inline">
									<input name="rwzb[{$key}][id]" value="{$vo.id}" placeholder="请输入" class="layui-input " type="text">
								</div>
								<label class="layui-form-label">名称</label>
								<div class="layui-input-inline">
									<input name="rwzb[{$key}][name]" value="[lv:{$vo.lv}]{$vo.name}" placeholder="请输入" class="layui-input " type="text">
								</div>
								<label class="layui-form-label">数量</label>
								<div class="layui-input-inline">
									<input name="rwzb[{$key}][num]" value="{$vo.num}" placeholder="请输入" class="layui-input" type="text">
								</div>
								<button class="layui-btn layui-btn-danger" onclick="delNum(this,1)" type="button">-</button>
							</div>
							{/foreach}
						</div>
					</div>
				</fieldset>
				<!-- / -->
				<fieldset class="layui-elem-field">
					<legend>奖励</legend>
					<div class="layui-field-box">
						<div class="layui-row" id="rwdj">
							<div class="layui-form-item">
								<label class="layui-form-label">道具</label>
								<button class="layui-btn ajax-reward" data-url="{:url('getMoldList')}" data-type="2" type="button">新增</button>
							</div>
							{foreach name='info.rwdj_list' item='vo'}
							<div class="layui-form-item">
								<label class="layui-form-label">ID</label>
								<div class="layui-input-inline">
									<input name="rwdj[{$key}][id]" value="{$vo.id}" placeholder="请输入" class="layui-input " type="text">
								</div>
								<label class="layui-form-label">名称</label>
								<div class="layui-input-inline">
									<input name="rwdj[{$key}][name]" value="{$vo.name}" placeholder="请输入" class="layui-input " type="text">
								</div>
								<label class="layui-form-label">数量</label>
								<div class="layui-input-inline">
									<input name="rwdj[{$key}][num]" value="{$vo.num}" placeholder="请输入" class="layui-input" type="text">
								</div>
								<button class="layui-btn layui-btn-danger" onclick="delNumProp(this)" type="button">-</button>
							</div>
							{/foreach}
						</div>
					</div>
				</fieldset>
				<!-- / -->
				<fieldset class="layui-elem-field">
					<legend>奖励</legend>
					<div class="layui-field-box">
						<div class="layui-row" id="rwyp">
							<div class="layui-form-item">
								<label class="layui-form-label">药品</label>
								<button class="layui-btn ajax-reward" data-url="{:url('getMoldList')}" data-type="3" type="button">新增</button>
							</div>
							{foreach name='info.rwyp_list' item='vo'}
							<div class="layui-form-item">
								<label class="layui-form-label">ID</label>
								<div class="layui-input-inline">
									<input name="rwyp[{$key}][id]" value="{$vo.id}" placeholder="请输入" class="layui-input " type="text">
								</div>
								<label class="layui-form-label">名称</label>
								<div class="layui-input-inline">
									<input name="rwyp[{$key}][name]" value="{$vo.name}" placeholder="请输入" class="layui-input " type="text">
								</div>
								<label class="layui-form-label">数量</label>
								<div class="layui-input-inline">
									<input name="rwyp[{$key}][num]" value="{$vo.num}" placeholder="请输入" class="layui-input" type="text">
								</div>
								<button class="layui-btn layui-btn-danger" onclick="delNumDrug(this)" type="button">-</button>
							</div>
							{/foreach}
						</div>
					</div>
				</fieldset>
				<!-- / -->
				<fieldset class="layui-elem-field">
					<legend>奖励</legend>
					<div class="layui-field-box">
						<div class="layui-row">
							<div class="layui-form-item">
								<label class="layui-form-label">技能</label>
								<div class="layui-input-inline">
									<select name="rwjineng">
										<option value="0">请选择</option>
										{volist name='listSkill' id='vo' key='k'}
										<option value="{$vo.jnid}" {if condition="$vo.jnid eq $info.jnname"}selected{/if}>[id:{$vo.jnid}]-{$vo.jnname}</option>
										{/volist}
									</select>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">修为</label>
								<div class="layui-input-inline">
									<input type="text" name="rwexp" value="{$info.rwexp|default='0'}" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">灵石</label>
								<div class="layui-input-inline">
									<input type="text" name="rwyxb" value="{$info.rwyxb|default='0'}" class="layui-input">
								</div>
							</div>
						</div>
					</div>
				</fieldset>
				<!-- / -->

				<div class="layui-input-block">
					<input type="hidden" name="rwid" type="hidden" value="{$info.rwid|default=''}">
					<button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</section>
		</form>
		<!--  -->
	</div>
</fieldset>
</body>
{/block}
{block name="script"}
<script>
layui.use(['jquery','form','laydate','upload','element'], function(){
	var $ = layui.jquery
	,laydate = layui.laydate
	,upload = layui.upload
	,element = layui.element
	,form = layui.form;

	$('.ajax-front').on('click',function(){
		var obj = $(this);
		var url = obj.data('url');
		var title = obj.data('title');

		var lv = $('#nlv').val();
		if(lv==0 || lv<0 || lv==''){
			layer.msg('请填写任务等级大于0', {icon:2,time:2000});
			return false;
		}

		url = url + '?ulv=' + lv;

		console.log('lv',lv);
		console.log('url',url);

		layer.open({
			type: 2,
			title: title,
			shadeClose: true, //是否点击遮罩关闭 默认：false
			maxmin: false, //开启最大化最小化按钮 默认：false
			area: ['500px', '400px'],
			content: url,
			btn: ['确定', '取消'],
			yes: function (index, layero) {
				var n = $(layero).find('iframe')[0];
				var objb = $(n).contents().find("select[name='task_id'] option:selected");
				var task_id = $(objb).val();
				var text = $(objb).text();

				console.log('id',task_id);
				console.log('name',text);

				$('#lastrwid').val(task_id);
				$('#lastrwid_name').val(text);

				layer.close(index);
			},
			btn2: function (index, layero) {
				layer.close(index);
			},
			cancel: function () {
				//右上角关闭回调
				return true //开启该代码可禁止点击该按钮关闭
			}
		});
	});

	form.on('radio(rwzl)', function(data){
		console.log(data.value);
		var rwzl = data.value;
		var title = '';
		var over = '';
		$('#rwcount_show').hide();
		$('#rwcount_ff').hide();

		if(rwzl==1){title = '收集';over = '收集数量';}
		if(rwzl==2){title = '打怪';over = '打怪数量';}
		if(rwzl==3){
			title = '对话';over = '提交对话';
			$('#rwcount_show').show();
			$('#rwcount_ff').show();
		}

		$('#need_title').text(title);
		$('#need_over').text(over);
	});

	$('.ajax-mold').on('click',function(){
		var obj = $(this);
		var url = obj.data('url');
		var alt = obj.data('alt');
		var title = obj.data('title');

		var value = $('input[name="rwzl"]:checked').val();
		if(value==1){
			url = url + '?type=2';
		}
		if(value==2){
			url = url + '?type=4';
		}
		if(value==3){
			url = url + '?type=5';
		}
		console.log('url',url);

		layer.open({
			type: 2,
			title: title,
			shadeClose: true, //是否点击遮罩关闭 默认：false
			maxmin: false, //开启最大化最小化按钮 默认：false
			area: ['500px', '400px'],
			content: url,
			btn: ['确定', '取消'],
			yes: function (index, layero) {
				var n = $(layero).find('iframe')[0];
				var objb = $(n).contents().find("select[name='mold'] option:selected");
				var id = $(objb).val();
				var text = $(objb).text();

				console.log('id',id);
				console.log('name',text);

				if(alt==1){
					$('#rwyq').val(id);
					$('#rwyq_name').val(text);
				}else{
					$('#rwcount').val(id);
					$('#rwcount_name').val(text);
				}

				layer.close(index);
			},
			btn2: function (index, layero) {
				layer.close(index);
			},
			cancel: function () {
				//右上角关闭回调
				return true //开启该代码可禁止点击该按钮关闭
			}
		});
	});

	$('.ajax-reward').on('click',function(){
		var obj = $(this);
		var url = obj.data('url');
		var type = obj.data('type');
		var title = obj.data('title');

		url = url + '?type=' + type;
		console.log('url',url);

		layer.open({
			type: 2,
			title: title,
			shadeClose: true, //是否点击遮罩关闭 默认：false
			maxmin: false, //开启最大化最小化按钮 默认：false
			area: ['500px', '400px'],
			content: url,
			btn: ['确定', '取消'],
			yes: function (index, layero) {
				var n = $(layero).find('iframe')[0];
				var objb = $(n).contents().find("select[name='mold'] option:selected");
				var id = $(objb).val();
				var text = $(objb).text();

				console.log('id',id);
				console.log('name',text);
				console.log('type',type);

				addHtml(id,text,type);

				layer.close(index);
			},
			btn2: function (index, layero) {
				layer.close(index);
			},
			cancel: function () {
				//右上角关闭回调
				return true //开启该代码可禁止点击该按钮关闭
			}
		})
	});

	form.render();
});
</script>
<script>
	var rwzb_list = "{$rwzb_list|default='1'}";
	var rwdj_list = "{$rwdj_list|default='1'}";
	var rwyp_list = "{$rwyp_list|default='1'}";

	layui.use(['jquery','form'], function(){
		var $ = layui.jquery
				,form = layui.form;

		window.addHtml = function(id,name,type) {
			var selector = '';
			var key = 1;
			if(type===1){key = rwzb_list;selector = 'rwzb';}
			if(type===2){key = rwdj_list;selector = 'rwdj';}
			if(type===3){key = rwyp_list;selector = 'rwyp';}

			$("#"+selector).append(
					"<div class='layui-form-item'>" +
					"<label class='layui-form-label'>ID</label>" +
					"<div class='layui-input-inline'>" +
					"<input type='text' name='"+selector+"["+key+"][id]' value='"+id+"' placeholder='请输入' class='layui-input'>" +
					"</div>" +
					"<label class='layui-form-label'>名称</label>" +
					"<div class='layui-input-inline'>" +
					"<input type='text' name='"+selector+"["+key+"][name]' value='"+name+"' placeholder='请输入' class='layui-input'>" +
					"</div>" +
					"<label class='layui-form-label'>数量</label>" +
					"<div class='layui-input-inline'>" +
					"<input type='text' name='"+selector+"["+key+"][num]' value='1' placeholder='请输入' class='layui-input'>" +
					"</div>" +
					"<button class='layui-btn layui-btn-danger' onclick='delNum(this,"+type+")' type='button'>-</button>" +
					"</div>");

			if(type===1){rwzb_list++;}
			if(type===2){rwdj_list++;}
			if(type===3){rwyp_list++;}
		}
	});

	function delNum(obj,type) {
		var $ = layui.jquery;
		$(obj).parent().remove();

		if(type===1){rwzb_list--;}
		if(type===2){rwdj_list--;}
		if(type===3){rwyp_list--;}
	}
</script>
{/block}